package com.joe.xl.common.util.redis;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.util.Objects;

public class RedissonPool {
    private volatile static RedissonClient redissonClient;

    private RedissonPool() {
    }

    public static RedissonClient getInstance() {
        try {
            if (Objects.isNull(redissonClient)) {
                Config config = new Config();
                config.useClusterServers()
                        .setScanInterval(10000) // 集群状态扫描间隔时间，单位是毫秒
                        //可以用"rediss://"来启用SSL连接
                        .addNodeAddress("redis://192.168.60.11:6379");
//                        .addNodeAddress("redis://10.10.20.48:7001", "redis://10.10.20.48:7002",
//                                "redis://10.10.20.48:7003", "redis://10.10.20.49:7001",
//                                "redis://10.10.20.49:7002", "redis://10.10.20.49:7003");
                synchronized (RedissonPool.class) {
                    if(null == redissonClient)
                        redissonClient = Redisson.create(config);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return redissonClient;
    }

}